package org.jspresso.model.service;
 
import org.jspresso.framework.application.backend.persistence.hibernate.HibernateBackendController;
import org.jspresso.framework.model.component.service.EmptyLifecycleInterceptor;
import org.jspresso.framework.model.entity.IEntityFactory;
import org.jspresso.framework.model.entity.IEntityLifecycleHandler;
import org.jspresso.framework.security.UserPrincipal;
import org.jspresso.model.BackActionTest;
import org.jspresso.tester.utils.TestEntitySerializer;

/**
 * Generated by Jspresso Developer Studio
 **/
public class BackActionTestInterceptors extends EmptyLifecycleInterceptor<BackActionTest> {
	@Override
	public boolean onPersist(BackActionTest component, IEntityFactory entityFactory, UserPrincipal principal,
			IEntityLifecycleHandler entityLifecycleHandler) {
		TestEntitySerializer.cleanOrphanGeneratedTestEntities(component.getTestScope(), (HibernateBackendController)entityLifecycleHandler);
		return super.onPersist(component, entityFactory, principal, entityLifecycleHandler);
	}
	
	@Override
	public boolean onUpdate(BackActionTest component, IEntityFactory entityFactory, UserPrincipal principal,
			IEntityLifecycleHandler entityLifecycleHandler) {
		TestEntitySerializer.cleanOrphanGeneratedTestEntities(component.getTestScope(), (HibernateBackendController)entityLifecycleHandler);
		return super.onUpdate(component, entityFactory, principal, entityLifecycleHandler);
	}

	/**
	 * Generated by Jspresso Developer Studio
	 **/
	@Override
	public boolean onCreate(BackActionTest backActionTest, IEntityFactory entityFactory, UserPrincipal principal,
			IEntityLifecycleHandler entityLifecycleHandler) {
		if(backActionTest.getTestScope() == null) { // Should always be true
			backActionTest.setTestScope(TestEntitySerializer.getDefaultScope((HibernateBackendController) entityLifecycleHandler));
			return true;
		}
		return false;
	}
	
}
